<template>
	<div class="content">
		<div class="banse">
			<el-card class="box-card">
				<div slot="header" class="clearfix">
					<span>订单基础信息</span>
					<el-button style="float: right;" type="primary" plain @click="go">返 回</el-button>
				</div>
				<div>
					<el-form ref="form" :model="form" label-width="0px">
						<el-row>
							<el-col>
								<el-form-item >
									订单ID：{{form.order_id}}
								</el-form-item>
							</el-col>
						</el-row>
						<el-row >
							<el-col :span="8">
								<el-form-item >
									产品名称：{{form.product_name || '暂无'}}
								</el-form-item>
								<el-form-item label="">
									里程碑：{{form.milepost  || '暂无'}}
								</el-form-item>
								<el-form-item label="" >
									客户属性：{{form.customer_type || '暂无'}}
								</el-form-item>
								<el-form-item label="" >
									状态：<el-tag :type="form.status == 1?'success':(form.status == 0?'warning':'danger')">{{form.status_show}}</el-tag>
								</el-form-item>
								<el-form-item label="" >
									样机：<span v-for="(item,index) in form.prototype" :key="index" style="margin: 0 5px;">
											<el-tag :type="item.length<=3?'success' : (item.length == 4 ? 'warning' : '')">{{item['name'] || '暂无'}}</el-tag>
										</span>
								</el-form-item>
								<el-form-item label="" >
									品牌属性：{{form.brand_type || '暂无'}}
								</el-form-item>
								<el-form-item label="" >
									联网方式：{{form.networking_mode  || '暂无'}}
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item >
									MODEL：{{form.project_name || '暂无'}}
								</el-form-item>
								<el-form-item label="">
									客户：{{form.customer || '暂无'}}
								</el-form-item>
								<el-form-item label="">
									产品线：{{form.product_line['name'] || '暂无'}}
								</el-form-item>
								<el-form-item label="">
									产品品类：{{form.product['name'] || '暂无'}}
								</el-form-item>
								<el-form-item label="">
									创建人：{{form.creator_show['name'] || '暂无'}}
								</el-form-item>
								<el-form-item label="" >
									销售区域：<el-tag type="success">{{form.sales_area || '暂无'}}</el-tag>
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item label="">
									测试组：{{form.group['name']}}
								</el-form-item>
								<el-form-item label="" >
									测试内容：<span v-for="(item,index) in getContent(form.test_content)" :key="index" style="margin: 0 3px;">
							<el-tag :type="item.length<=3?'success' : (item.length == 4 ? 'warning' : '')">{{item}}</el-tag>
						</span>
								</el-form-item>
								<el-form-item label="" >
									创建时间：{{getTime(form.create_time)}}
								</el-form-item>
								<el-form-item label="" >
									更新时间：{{getTime(form.update_time)}}
								</el-form-item>
								<el-form-item label="" >
									服务器：<el-tag type="warning">{{form.server || '暂无'}}</el-tag>
								</el-form-item>
								<el-form-item label="" >
									计划时间：
									<span v-if="form.start_time">
										<span>{{ getJtime(form.start_time) }}</span> ~ <span>{{ getJtime(form.end_time) }}</span>
									</span>
									<span v-else>暂 无</span>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
			</el-card>
		</div>

		<div class="tab">
			<el-card class="box-card">
				<div slot="header" class="clearfix">
					<span>测试用例</span>
				</div>
				<div>
					<el-form ref="form" :model="form" label-width="0px">
						<el-row >
							<el-col :span="8">
								<el-form-item >
									用例总数：{{formTest.all_count}}
								</el-form-item>
								<el-form-item label="">
									通过数量：{{formTest.pass_count}}
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item label="">
									正在测试：{{formTest.testing}}
								</el-form-item>
								<el-form-item >
									测试完成：{{formTest.test_done}}
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item >
									等待测试：{{formTest.waiting_test}}
								</el-form-item>
								<el-form-item >
									失败数量：{{formTest.fail_count}}
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="caseLst">

					<div class="tabList">
						<el-collapse v-model="activeNames" >
							<el-collapse-item title="测试用例列表（可展开）" name="1">
								<el-tabs v-model="activeName" @tab-click="handleClick">
									<el-tab-pane label="IoT产品通用" name="first">
										<div class="item">
											<div class="case">
												<div class="caseItem">
													<span>测试状态</span>
													<el-select v-model="status"  clearable @change="statusChange" placeholder="请选择状态">
														<el-option label="待测试" value="待测试"></el-option>
														<el-option label="正在测试" value="正在测试"></el-option>
														<el-option label="测试完成" value="测试完成"></el-option>
													</el-select>
												</div>
												<div class="caseItem" style="margin-left: 5px;">
													<div class="file">
														<div class="item">
															<el-upload
																class="upload-demo"
																action="string"
																:headers="headers"
																:show-file-list="false"
																:http-request="uploadFile"
																:on-remove="deleteFile"
																:before-upload="beforeUpload">
																<el-button size="small" type="primary">导入用例</el-button>
															</el-upload>
														</div>
														<div class="item">
															<el-button type="success" size="small">
																<a :href="href" style="color: #fff;">下载模板</a>
															</el-button>
														</div>
													</div>

												</div>
											</div>
											<div class="case">
												<el-button type="success" @click="delCase">批量删除</el-button>
												<el-button type="primary" @click="brush">刷 新</el-button>
											</div>
										</div>
										<div class="testTable">
											<el-table
												v-if="tableData"
												class="marT"
												:data="tableData"
												:border="true"
												:header-cell-style="{background:'#eef1f6'}"
												lazy
												@selection-change="handleSelectionChange"
												row-key="id">
												<el-table-column
													type="selection"
													width="55">
												</el-table-column>
												<el-table-column align="center" type="index" label="序号" width="50">
												</el-table-column>
												<el-table-column align="center" property="case_name" label="用例标题" width="300"></el-table-column>
												<el-table-column align="center" property="priority" label="优先级" width="100"></el-table-column>
												<el-table-column align="center" property="test_type" label="测试类型" width="100"></el-table-column>
												<el-table-column align="center" property="test_module" label="测试模型" width="150"></el-table-column>
												<el-table-column align="center" property="test_module" label="测试状态" width="100">
													<template slot-scope="scope">
														<el-tag v-if="scope.row.status == 0" >删除</el-tag>
														<el-tag v-if="scope.row.status == 1" type="success" >待测试</el-tag>
														<el-tag v-if="scope.row.status == 2" type="info" >正在测试</el-tag>
														<el-tag v-if="scope.row.status == 3" type="warning" >测试完成</el-tag>
													</template>
												</el-table-column>
												<el-table-column align="center" property="task_cases" label="测试记录" >
													<template slot-scope="scope">
												<span v-for="(item,index) in scope.row.task_cases" :key="index">
													<el-popover effect="dark" placement="top" trigger="hover">
														<div style="overflow: auto;">
															<div style="padding: 10px;" >
															<div v-if="item.status == 0">
																<span>测试人：{{item.tester_show || '暂无'}}</span><br/>
									　							 <span>更新时间：{{getTime(item.update_time)}}</span>
															</div>
															<div v-if="item.status != 0">
																<span>测试人：{{item.tester_show['name'] || '暂无'}}</span><br/>
																<span>状  态：{{item.status_show || '暂无'}}</span><br/>
																<span :class="item.result == 'PASS'?'pass':'fail'">结  果：{{item.result || '暂无'}}</span><br/>
										　						<span>更新时间：{{getTime(item.update_time)}}</span>
															</div>
														</div>
														</div>
														<el-button slot="reference" type="primary" size="mini" style="margin: 5px;" plain v-if="item.status == 0">待测试</el-button>
														<el-button slot="reference" :type="item.result == 'FAIL'?'danger':'success'" size="mini" style="margin: 5px;" plain v-if="item.status != 0">{{item.result}}</el-button>
													</el-popover>
												</span>
													</template>
												</el-table-column>
												<el-table-column align="center" label="操作" width="150">
													<template slot-scope="scope">
												<span>
													<template>
														<el-popconfirm title="确认删除吗？" @confirm="del(scope.row)">
															<span slot="reference" class="del">删除</span>
														</el-popconfirm>
													</template>
												</span>
														<span><a > | </a></span>
														<span><a @click="edit(scope.row)" >修改</a></span>
													</template>
												</el-table-column>
											</el-table>
										</div>
									</el-tab-pane>
									<el-tab-pane label="品类通用" name="second">
										<div class="item">
											<div class="case">
												<div class="caseItem">
													<span>测试状态</span>
													<el-select v-model="status"  clearable @change="statusChange" placeholder="请选择状态">
														<el-option label="待测试" value="待测试"></el-option>
														<el-option label="正在测试" value="正在测试"></el-option>
														<el-option label="测试完成" value="测试完成"></el-option>
													</el-select>
												</div>
												<div class="caseItem" style="margin-left: 5px;">
													<div class="file">
														<div class="item">
															<el-upload
																class="upload-demo"
																action="string"
																:headers="headers"
																:show-file-list="false"
																:http-request="uploadFile"
																:on-remove="deleteFile"
																:before-upload="beforeUpload">
																<el-button size="small" type="primary">导入用例</el-button>
															</el-upload>
														</div>
														<div class="item">
															<el-button type="success" size="small">
																<a :href="href" style="color: #fff;">下载模板</a>
															</el-button>
														</div>
													</div>

												</div>
											</div>
											<div class="case">
												<el-button type="success" @click="delCase">批量删除</el-button>
												<el-button type="primary" @click="brush">刷 新</el-button>
											</div>
										</div>
										<div class="testTable">
											<el-table
												v-if="commonList"
												class="marT"
												:data="commonList"
												:border="true"
												:header-cell-style="{background:'#eef1f6'}"
												lazy
												@selection-change="handleSelectionChange"
												row-key="id">
												<el-table-column
													type="selection"
													width="55">
												</el-table-column>
												<el-table-column align="center" type="index" label="序号" width="50">
												</el-table-column>
												<el-table-column align="center" property="case_name" label="用例标题" width="300"></el-table-column>
												<el-table-column align="center" property="priority" label="优先级" width="100"></el-table-column>
												<el-table-column align="center" property="test_type" label="测试类型" width="100"></el-table-column>
												<el-table-column align="center" property="test_module" label="测试模型" width="150"></el-table-column>
												<el-table-column align="center" property="test_module" label="测试状态" width="100">
													<template slot-scope="scope">
														<el-tag v-if="scope.row.status == 0" >删除</el-tag>
														<el-tag v-if="scope.row.status == 1" type="success" >待测试</el-tag>
														<el-tag v-if="scope.row.status == 2" type="info" >正在测试</el-tag>
														<el-tag v-if="scope.row.status == 3" type="warning" >测试完成</el-tag>
													</template>
												</el-table-column>
												<el-table-column align="center" property="task_cases" label="测试记录" >
													<template slot-scope="scope">
												<span v-for="(item,index) in scope.row.task_cases" :key="index">
													<el-popover effect="dark" placement="top" trigger="hover">
														<div style="overflow: auto;">
															<div style="padding: 10px;" >
															<div v-if="item.status == 0">
																<span>测试人：{{item.tester_show || '暂无'}}</span><br/>
									　							 <span>更新时间：{{getTime(item.update_time)}}</span>
															</div>
															<div v-if="item.status != 0">
																<span>测试人：{{item.tester_show['name'] || '暂无'}}</span><br/>
																<span>状  态：{{item.status_show || '暂无'}}</span><br/>
																<span :class="item.result == 'PASS'?'pass':'fail'">结  果：{{item.result || '暂无'}}</span><br/>
										　						<span>更新时间：{{getTime(item.update_time)}}</span>
															</div>
														</div>
														</div>
														<el-button slot="reference" type="primary" size="mini" style="margin: 5px;" plain v-if="item.status == 0">待测试</el-button>
														<el-button slot="reference" :type="item.result == 'FAIL'?'danger':'success'" size="mini" style="margin: 5px;" plain v-if="item.status != 0">{{item.result}}</el-button>
													</el-popover>
												</span>
													</template>
												</el-table-column>
												<el-table-column align="center" label="操作" width="150">
													<template slot-scope="scope">
												<span>
													<template>
														<el-popconfirm title="确认删除吗？" @confirm="del(scope.row)">
															<span slot="reference" class="del">删除</span>
														</el-popconfirm>
													</template>
												</span>
														<span><a > | </a></span>
														<span><a @click="edit(scope.row)" >修改</a></span>
													</template>
												</el-table-column>
											</el-table>
										</div>
									</el-tab-pane>
									<el-tab-pane label="品类特有" name="third">
										<div class="item">
											<div class="case">
												<div class="caseItem">
													<span>测试状态</span>
													<el-select v-model="status"  clearable @change="statusChange" placeholder="请选择状态">
														<el-option label="待测试" value="待测试"></el-option>
														<el-option label="正在测试" value="正在测试"></el-option>
														<el-option label="测试完成" value="测试完成"></el-option>
													</el-select>
												</div>
												<div class="caseItem" style="margin-left: 5px;">
													<div class="file">
														<div class="item">
															<el-upload
																class="upload-demo"
																action="string"
																:headers="headers"
																:show-file-list="false"
																:http-request="uploadFile"
																:on-remove="deleteFile"
																:before-upload="beforeUpload">
																<el-button size="small" type="primary">导入用例</el-button>
															</el-upload>
														</div>
														<div class="item">
															<el-button type="success" size="small">
																<a :href="href" style="color: #fff;">下载模板</a>
															</el-button>
														</div>
													</div>

												</div>
											</div>
											<div class="case">
												<el-button type="success" @click="delCase">批量删除</el-button>
												<el-button type="primary" @click="brush">刷 新</el-button>
											</div>
										</div>
										<div class="testTable">
											<el-table
												v-if="specificList"
												class="marT"
												:data="specificList"
												:border="true"
												:header-cell-style="{background:'#eef1f6'}"
												lazy
												@selection-change="handleSelectionChange"
												row-key="id">
												<el-table-column
													type="selection"
													width="55">
												</el-table-column>
												<el-table-column align="center" type="index" label="序号" width="50">
												</el-table-column>
												<el-table-column align="center" property="case_name" label="用例标题" width="300"></el-table-column>
												<el-table-column align="center" property="priority" label="优先级" width="100"></el-table-column>
												<el-table-column align="center" property="test_type" label="测试类型" width="100"></el-table-column>
												<el-table-column align="center" property="test_module" label="测试模型" width="150"></el-table-column>
												<el-table-column align="center" property="test_module" label="测试状态" width="100">
													<template slot-scope="scope">
														<el-tag v-if="scope.row.status == 0" >删除</el-tag>
														<el-tag v-if="scope.row.status == 1" type="success" >待测试</el-tag>
														<el-tag v-if="scope.row.status == 2" type="info" >正在测试</el-tag>
														<el-tag v-if="scope.row.status == 3" type="warning" >测试完成</el-tag>
													</template>
												</el-table-column>
												<el-table-column align="center" property="task_cases" label="测试记录" >
													<template slot-scope="scope">
												<span v-for="(item,index) in scope.row.task_cases" :key="index">
													<el-popover effect="dark" placement="top" trigger="hover">
														<div style="overflow: auto;">
															<div style="padding: 10px;" >
															<div v-if="item.status == 0">
																<span>测试人：{{item.tester_show || '暂无'}}</span><br/>
									　							 <span>更新时间：{{getTime(item.update_time)}}</span>
															</div>
															<div v-if="item.status != 0">
																<span>测试人：{{item.tester_show['name'] || '暂无'}}</span><br/>
																<span>状  态：{{item.status_show || '暂无'}}</span><br/>
																<span :class="item.result == 'PASS'?'pass':'fail'">结  果：{{item.result || '暂无'}}</span><br/>
										　						<span>更新时间：{{getTime(item.update_time)}}</span>
															</div>
														</div>
														</div>
														<el-button slot="reference" type="primary" size="mini" style="margin: 5px;" plain v-if="item.status == 0">待测试</el-button>
														<el-button slot="reference" :type="item.result == 'FAIL'?'danger':'success'" size="mini" style="margin: 5px;" plain v-if="item.status != 0">{{item.result}}</el-button>
													</el-popover>
												</span>
													</template>
												</el-table-column>
												<el-table-column align="center" label="操作" width="150">
													<template slot-scope="scope">
												<span>
													<template>
														<el-popconfirm title="确认删除吗？" @confirm="del(scope.row)">
															<span slot="reference" class="del">删除</span>
														</el-popconfirm>
													</template>
												</span>
														<span><a > | </a></span>
														<span><a @click="edit(scope.row)" >修改</a></span>
													</template>
												</el-table-column>
											</el-table>
										</div>
									</el-tab-pane>
								</el-tabs>

							</el-collapse-item>
						</el-collapse>
					</div>

				</div>
			</el-card>
		</div>
		<div class="task">
			<el-card class="box-card">
				<div slot="header" class="clearfix">
					<span>测试任务</span>
					<el-button style="float: right;" type="primary" plain @click="addTask(form)" v-if="power.includes('order_create_task')">新 增</el-button>
				</div>
				<div class="taskL">
					<el-table
						v-if="taskList"
						class="marT"
						:data="taskList"
						:border="true"
						:header-cell-style="{background:'#eef1f6'}"
						lazy
						row-key="id">
						<el-table-column align="center" type="index" label="序号" width="50">
						</el-table-column>
						<el-table-column align="center" property="task_name" label="任务名称" width="180"></el-table-column>
						<el-table-column align="center" property="task_type" label="任务类型">
							<template slot-scope="scope">
								<el-tag v-if="scope.row.task_type == '预测试'" >预测试</el-tag>
								<el-tag v-if="scope.row.task_type == '首次提测'" type="success" >首次提测</el-tag>
								<el-tag v-if="scope.row.task_type == '复测'" type="warning" >复测</el-tag>
							</template>
						</el-table-column>
						<el-table-column align="center" property="task_id" label="任务ID" width="180"></el-table-column>
						<el-table-column align="center" property="case_statistic" label="任务进度">
							<template slot-scope="scope">
								<span>{{getStatistic(scope.row.case_statistic)}}</span>
							</template>
						</el-table-column>
						<el-table-column align="center" property="manpower" label="人力需求" ></el-table-column>
						<el-table-column align="center" property="android_version" label="Android版本" ></el-table-column>
						<el-table-column align="center" property="unit_version" label="插件版本" ></el-table-column>
						<el-table-column align="center" property="firmware_version" label="固件版本" ></el-table-column>
						<el-table-column align="center" property="test_suite_url" label="测试套件地址" width="200"></el-table-column>
						<el-table-column align="center" property="status" label="测试状态" width="200">
							<template slot-scope="scope">
								<el-tag v-if="scope.row.status == 0" >{{scope.row.status_show}}</el-tag>
								<el-tag v-else-if="scope.row.status == 1" type="success" >{{scope.row.status_show}}</el-tag>
								<el-tag v-else-if="scope.row.status == 2" type="warning" >{{scope.row.status_show}}</el-tag>
								<el-tag v-else type="danger" >{{scope.row.status_show}}</el-tag>
							</template>
						</el-table-column>
						<el-table-column align="center" label="操作" width="150" fixed="right">
							<template slot-scope="scope">
								<span><a @click="see(scope.row.id)" >查看详情</a></span>
							</template>
						</el-table-column>
					</el-table>
				</div>
			</el-card>
		</div>
		<testCaseEdit ref="testCaseEdit"></testCaseEdit>
		<taskAddForm ref="taskAddForm"></taskAddForm>
	</div>

</template>

<script>
import { getHeader } from '@/app.config'
import { orderDetail, statistic, orderCase, orderTask, orderIdCase,
	caseTemplate,orderMult} from '@/api/user'

import testCaseEdit from './model/testCaseEdit'
import taskAddForm from './taskModel/addForm'

import moment from 'moment'

export default {
	components:{
		testCaseEdit,
		taskAddForm
	},
	data(){
		return {
			commonType:'iot_common',
			activeName:'first',
			href:'',
			form:{
				product_line:{name:''},
				product:{name:''},
				creator_show:{name:''},
				group:{name:''},
				test_content:[],
				server:[]
			},
			id:'',
			activeNames:1,

			initTableList:[],
			tableData:[], //  IoT产品通用用例列表
			commonList:[],    //  品类通用用例列表
			specificList:[],  //  品类特有用例列表

			taskList:[],
			formTest:{},
			table:[],
			status:'',
			result:'',
			headers:{'Content-Type':'multipart/form-data'},
			power:[]
		}
	},
	created() {
		this.id = this.$route.params.id
		this.initData(this.$route.params.id)
	},
	methods:{
		// 切换用例标签页
		handleClick(){
			if(this.activeName == 'first'){
				this.commonType = 'iot_common'
			}
			if(this.activeName == 'second'){
				this.commonType = 'common'
			}if(this.activeName == 'third'){
				this.commonType = 'specific'
			}
		},
		// 全选用例
		handleSelectionChange(val) {
			let arr = []
			val.forEach(item => {
				arr.push(item.id)
			})
			this.multipleSelection = arr;
		},
		delCase(){
			var data = {
				case_ids:this.multipleSelection
			}
			orderMult(data).then(res => {
				if(res.status == 'success'){
					this.$message.success('删除成功！')
					this.getDetail()
				}else {
					this.$message.error('删除失败！')
				}
			})
		},
		//任务进度
		getStatistic(data){
			let a = parseInt(data['all_count'])
			let b = parseInt(data['test_done_count'])
			let num = (b/a)*100
			return num.toFixed(2)+'%'
		},
		// 新增任务
		addTask(data){
			this.$refs.taskAddForm.dialogFormVisible = true
			this.$refs.taskAddForm.initData(data)
		},
		getContent(data){
			let name = []
			data.filter((item,index) => {
				name.push(item['test_content'])
			})
			return name
		},
		getServer(data){
			let name = []
			data.forEach((item,index) => {
				name.push(item['server'])
			})
			return name
		},
		// 测试状态
		statusChange(e){
			console.log(e,121212)
			let arr = []
			if(e != ''){
				this.initTableList.filter(item => {
					if(item['status_show']==e && item['type']==this.commonType){
						arr.push(item)
					}
				})
				if(this.commonType == 'iot_common'){
					this.tableData = arr
				}
				if(this.commonType == 'common'){
					this.commonList = arr
				}
				if(this.commonType == 'specific'){
					this.specificList = arr
				}
			}else {
				this.getDetail()
			}

		},
		// 测试结果
		resultChange(e){
			this.selectTab(this.status,e)
		},
		// 刷新按钮
		brush(){
			this.getDetail()
		},
		// 查询
		selectTab(status,result){
			let arr = []
			if(result == ''){
				this.initTableList.filter(item => {
					if(item['status_show']==status){
						arr.push(item)
					}
				})
				if(this.commonType == 'iot_common'){
					this.tableData = arr
				}
				if(this.commonType == 'common'){
					this.commonList = arr
				}
				if(this.commonType == 'specific'){
					this.specificList = arr
				}

			}
			if(status == ''){
				this.initTableList.filter(item => {
					if(item['result']==result){
						arr.push(item)
					}
				})
				if(this.commonType == 'iot_common'){
					this.tableData = arr
				}
				if(this.commonType == 'common'){
					this.commonList = arr
				}
				if(this.commonType == 'specific'){
					this.specificList = arr
				}
			}
			if(status && result){
				this.initTableList.filter(item => {
					if(item['status_show']==status && item['result']==result){
						arr.push(item)
					}
				})
				if(this.commonType == 'iot_common'){
					this.tableData = arr
				}
				if(this.commonType == 'common'){
					this.commonList = arr
				}
				if(this.commonType == 'specific'){
					this.specificList = arr
				}
			}
			if(status == '' && result == ''){
				this.getDetail()
			}
		},
		// 删除用例
		del(data){
			orderCase(data.id).then(res => {
				if(res.status == 'success'){
					this.$message.success('删除成功！')
					this.getDetail()
				}else {
					this.$message.error('删除失败！')
				}
			})
		},
		// 修改用例
		edit(data){
			this.$refs.testCaseEdit.initTab(data)
		},
		deleteFile(file, fileList) {
			this.$message.success("成功移除!")
			this.form.guidance_doc.forEach((item,index) => {
				var arr = item.split('/')
				if(file.name == arr[arr.length-1] ){
					if(index != 0){
						this.form.guidance_doc.splice(index,index)
					}else {
						this.form.guidance_doc = []
					}
				}
			})
		},
		beforeUpload(file){
			var type = file.name
			type = type.split('.')[1]
		},
		// 获取用例详情
		getDetail(){
			let iot_common = []
			let common = []
			let specific = []
			orderIdCase(this.id).then(res => {
				this.initTableList = res.data
				res.data.forEach(item => {
					if(item.type == 'common'){
						common.push(item)
					}
					if(item.type == 'iot_common'){
						iot_common.push(item)
					}
					if(item.type == 'specific'){
						specific.push(item)
					}
				})
				this.tableData = iot_common  //  IoT产品通用用例列表
				this.commonList = common    //  品类通用用例列表
				this.specificList = specific  //  品类特有用例列表
			})
		},
		//上传附件
		uploadFile(file) {
			let url= `${process.env.VUE_APP_KANBAN_HOST}/api/v1/order/${this.id}/import/case?type=${this.commonType}`
			let fd = new FormData();
			fd.append('file',file.file);
			this.$axios.post(url,fd,{headers: getHeader()})
				.then((response) => {
					if (response.data.status == 'success') {
						this.$message.success("上传成功!")

						this.getDetail()

						statistic(this.id).then(res => {
							this.formTest = Object.assign({},res.data)
						})
					}
				}).catch((err) => {
				console.log(err);
			});
		},
		go(){
			this.$router.go(-1)
		},
		initData(data){
			let iot_common = []
			let common = []
			let specific = []

			caseTemplate().then(res => {
				this.href = res.data
			})

			this.power = sessionStorage.getItem('power').split(',')

			orderDetail(data).then(res => {
				this.form = Object.assign({},res.data)
			})
			statistic(data).then(res => {
				this.formTest = Object.assign({},res.data)
			})
			orderTask(data).then(res => {
				console.log(res,121212)
				this.taskList = res.data
			})
			orderIdCase(data).then(res => {
				this.initTableList = res.data

				res.data.forEach(item => {
					if(item.type == 'common'){
						common.push(item)
					}
					if(item.type == 'iot_common'){
						iot_common.push(item)
					}
					if(item.type == 'specific'){
						specific.push(item)
					}
				})
				this.tableData = iot_common  //  IoT产品通用用例列表
				this.commonList = common    //  品类通用用例列表
				this.specificList = specific  //  品类特有用例列表
			})
		},
		getTime(data){
			var d = new Date(data);
			var d2 = d.getTime() - 8 * 60 * 60 * 1000
			d = new Date(d2)
			var  resDate = d.getFullYear() + '-' +
				((d.getMonth() + 1)<10?'0'+(d.getMonth() + 1):(d.getMonth() + 1)) + '-' +
				(d.getDate()<10?'0'+d.getDate():d.getDate())+ ' '+
				(d.getHours()<10?'0'+d.getHours():d.getHours())+':'+
				(d.getMinutes()<10?'0'+d.getMinutes():d.getMinutes())+':'+
				(d.getSeconds()<10?'0'+d.getSeconds():d.getSeconds());
			return resDate
		},
		getJtime(data){
			let time = moment(data).format('YYYY-MM-DD HH:mm:ss')
			return time
		},
		see(data){
			this.$router.push(`/detailTask/${data}`)
		}
	}
}
</script>

<style lang="scss" scoped>
.content{
	padding: 0 10px;
	margin-bottom: 50px;
	min-height: 1000px;
}
.banse{
	margin-top: 10px;
}
.testTable{
	height: 430px;
	overflow:scroll;
}
.file{
	display: flex;
}
.file .item:last-child{
	margin-left: 10px;
}
.tab{
	margin: 15px 0;
}
.caseLst .tabList .item{
	display: flex;
	justify-content: space-between;
}
.caseLst .tabList .item .case:first-child{
	display: flex;
	margin-bottom: 15px;
}
.del{
	color: #1890FF;
	cursor: pointer;
}
.pass{
	color: green;
}
.fail{
	color: red;
}
</style>
